Facebook: Sending private messages to FB profile from a static website [migrated]

Posted by Frondor on Pro Webmasters See other posts from Pro Webmasters or by Frondor
Published on 2014-08-20T12:49:55Z Indexed on 2014/08/20 16:36 UTC
Read the original article Hit count: 306

Filed under:
|
|
|

I need to setup a static website for people to: Complete a form. And using anything from Facebook API, GET the form output via message to a Facebook Profile. I've been punching my head against "facebook developers" page all night long and can't find out how to do it. Seems quite easy, but the problem is that I don't know if you'll get my point :)

Like the Send Dialog feature, you can set a certain user as recipient which will be displayed on the "To:" field once the dialog appears.

FB.ui({
  method: 'send',
to: 'UserID',
  link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html',
});

Ok, All I need is to be able to use the same behavior but instead of setting a "to:" parameter, I'd like to set a "message:" parameter. I don't know how I can solve this becuase there's no parameter like this on the API actually.

This is what I need to build (It's a prototype, this code won't work)

<form action="mysite.com" id="order">
<input type="radio" name="chocolate" value="white">White <br/>
<input type="radio" name="chocolate" value="black">Black <br/>
<input type="submit" value="Order" />
</form>

jQuery gets the values

$(document).ready(function() {
   $("#order").on("submit", function(e) {
      e.preventDefault();
      var formOutput = $(this).serialize();
      var order = "I'd like to eat" + formOutput + "chocolate";
   });
});

Facebook sdk sends this output ('order' string)

FB.ui({
    method: 'send', //or whatever
    to: 'UserID',
    message: order, //Its just an example, note the variable coming from the form
    link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html',
});

As we all know, what I wrote isn't possible, so I'm asking for any alternative solution if somebody can give me, I'm not very friendly with facebook APIs :)

I though in another solution which consist in using the form output directly on the 'link:' parameter of FB.ui and then reading it with jQuery on some landing page. For example, on the message sent, the linked content redirects to this URL:

http://mysite.com/dashboard.html?chocolate=white

and the dashboard page source code:

<script>
var choco = getUrlParameter('chocolate');
$("#dashboard").text("This person wants" + choco + "chocolate")
</script>
<div id="dashboard"></div>

And this way, I will be able to see which kind of chocolate the person selected by parsing some parameters on the URL when clicking on the link section of the message: send dialog

using a code like this:

FB.ui({
    method: 'send', //or whatever
    to: 'MyUserID',
    link: 'http://mysite.com/dashboard.html?chocolate=white',
});

But no this try, my biggest problem is that I don't know how to dynamically "customize" that "link:" paramenter with jQuery. I think the best solution is to use a code like this along with the dashboard page in order to "translate" the shared URLs and see what kind of chocolate people are demanding xD

   FB.ui({

//declaring a variable (example)
var string = getFormData().serialize;
var orderString = "mysite.com/dashboard.html?" + string;
// end the variables
// start facebook API code

        method: 'send', //or whatever
        to: 'MyUserID',
        link: orderString,
    });

I was working here until I gave up and started to post this

http://jsfiddle.net/Frondor/sctepn06/2/

Thanks in advance, I'll love you for ever if you help me solving this :D

© Pro Webmasters or respective owner

Related posts about JavaScript

Related posts about facebook